<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" href="skin/base.css">
<link rel="stylesheet" href="skin/talk.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body>
<div id="main" class="loading"> </div>
</body>
<script>
	zy_init();
	var uplist = {};
	var photonum = 0;
	var photon = -1;
	var talk_ask_id=0;
	
	var page=1;
	var min=0;
	var isopen = false;
	
	var userid = 0;
	if (typeof(localStorage['userid']) != "undefined") {
		userid = parseInt(localStorage['userid']);
		window.localStorage.removeItem('userid');
	}
	
	function ok_ask(){
		talk_ask_id = localStorage['talk_ask_id'];
		photonum = 0;
	    photon = -1;
		
		if (typeof(localStorage['talk_ask_uplist']) != "undefined") {
			uplist = getStorJson('talk_ask_uplist');
			
			for (var i in uplist['url']) {
				photonum++;
			}
			
			if (photonum > 0) {
				uexWindow.evaluateScript('talk', '0', "$$('talkup').className = 'up bg'");
				uploadPhoto();
			}else{
				uexWindow.toast("0", "5", '发布成功~', 1000);
				getMain(0);
			}
		}
	}
	
	function ok_answer(){
		uexWindow.toast("0", "5", '回复成功~', 1000);
		getMain(0);
	}
	
	function uploadPhoto(){
		photon++;
		if(photon<photonum){
		    uexUploaderMgr.onStatus = function(opCode, fileSize, percent, re, status){
		        switch (status) {
		            case 0:
						//newNode.innerHTML = '<div>' + percent + "%" + '</div>';
		                break;
		            case 1:
						uexUploaderMgr.closeUploader(1);
						re = JSON.parse(re);
						if (re['success'] == 'OK') {
							uploadPhoto();
						}else{
							uploadPhoto();
						}
		                break;
		            case 2:
		                uexUploaderMgr.closeUploader(1);
						uploadPhoto();
		                break;
		        }
		    }
			
		    uexUploaderMgr.cbCreateUploader = function(opCode, dataType, data){
		        if (data != 0) {
					uexUploaderMgr.closeUploader(1);
					uploadPhoto();
		        }
		    }
			
			var url = app_path+'index.php?m=iappTalk&c=app&a=talkupload'+
							   '&type='+uplist['type'][photon]+'&num='+photonum+'&id='+talk_ask_id+
							   '&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
		    uexUploaderMgr.createUploader(1, url);
		    uexUploaderMgr.uploadFile(1, uplist['url'][photon], "fname", 0);
				
		}else{
			uexWindow.toast("0", "5", '发布成功~', 1000);
			uexWindow.evaluateScript('talk','0',"$$('talkup').className = 'up'");
			getMain(0);
		}
	}
	
	function jump(id){
		localStorage['talk_id']=id;
		uexWindow.open('talk_show','0','talk_show.html','2','', '',0);
	}
	
	function user_talk(userid,nickname){
		localStorage['userid'] = userid;
		localStorage['user_home_nickname'] = nickname;
		uexWindow.open('user_talk', '0', 'user_talk.html', 2, '', '', 0);
	}
	
	function audioPlay(url,id){
		uexAudio.closeSoundPool();
		if(!isopen){
			$$(id).className="voice stop";
			uexAudio.open(url);
			uexAudio.play(0);
			isopen = true;
		}else{
			$$(id).className="voice";
			uexAudio.stop();
			isopen = false;
		}
    }
    
	function praise(id){
		if (!c_l()) {
			gologin();
			return false;
		}
		
		var url = app_path+'index.php?m=iappTalk&c=app&a=praise&id='+id+'&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
		uexXmlHttpMgr.open(2,'post',url,"8000");
		uexXmlHttpMgr.send(2);
	}
	
	function del(id){
		if (!c_l()) {
			gologin();
			return false;
		}
		
		uexWindow.cbActionSheet = function(opId,dataType,data){
			if(dataType==2){
				if(data==0){
					var url = app_path+'index.php?m=iappTalk&c=app&a=del&id='+id+'&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];	
					uexXmlHttpMgr.open(3,'post',url,"8000");
					uexXmlHttpMgr.send(3);
				}
			}
		}
		uexWindow.actionSheet('你确定要删除这条说说吗？','取消',['确定删除']);
	}
	
	function printobj(obj){
		var msg = '';
		for (var item in obj) {
			msg += item + ":" + obj[item]+'\n';
		}
		alert(msg);
	}
	
	function ImageBrowser(pictureurls,index){
		var data= pictureurls.split(","); 
		uexImageBrowser.open(data, index, 1);
	}
	
	function getMain(t){	
		if(t==0){
			min=0;
			page=1;
		}
		var url = app_path+'index.php?m=iappTalk&c=app&a=lists&order='+localStorage['talk_list_order']+'&page='+page;
		if(userid>0){
			url = app_path+'index.php?m=iappTalk&c=app&a=lists&order='+localStorage['talk_list_order']+'&page='+page+'&userid='+userid;
		}
		
		uexXmlHttpMgr.open(t,'post',url,"8000");
		uexXmlHttpMgr.send(t);
	}
	
	
	window.uexOnload=function(type){
		if (!type) {
			uexWindow.setBounce("1");
			uexWindow.setBounceParams("0",'{"textColor":"#666","levelText":"","pullToReloadText":"拖动刷新","releaseToReloadText":"释放刷新","loadingText":"加载中，请稍等"}');
			uexWindow.setBounceParams("1",'{"textColor":"#666","levelText":"","pullToReloadText":"上拉加载更多","releaseToReloadText":"释放加载","loadingText":"加载中，请稍等"}');
			uexWindow.showBounceView("0","#f3f3f3","1");
			uexWindow.notifyBounceEvent("0","1");
			uexWindow.showBounceView("1","#f3f3f3","1");
			uexWindow.notifyBounceEvent("1","1");
			uexWindow.onBounceStateChange=function(t,s){
　　　　　　		if(t=="0"||t=="1"){
　　　　　　　　		if(s=="2"){
						getMain(t);						
					}
　　　　　　		}
			}
			
			uexXmlHttpMgr.onData = function(opId, status, data){
				uexXmlHttpMgr.close(opId);
				uexWindow.resetBounceView(opId);
				if(status==1){
					data=JSON.parse(data);
					if(opId==0 || opId==1){//列表
						if(opId==0){
							uexWindow.setBounceParams("0",'{"textColor":"#666","levelText":"上次更新：'+Now()+'","pullToReloadText":"拖动刷新","releaseToReloadText":"释放刷新","loadingText":"加载中，请稍等"}');
							$$('main').innerHTML='';
						}
						$$('main').className = '';
						InsertHtml(data['lists']);
						page++;
					}else if(opId==-1){//图片上传
						photon++;
						uploadPhoto(-1, photon);
					}else if(opId==2){//赞
						if(data['success']=='NOTLOGIN'){
							gologin();
						}else if(data['success']=='OK'){
							var pn = parseInt($$("praise_"+data['data']['id']).innerHTML)+1;
							$$("praise_"+data['data']['id']).innerHTML=pn;
							$$("praise_"+data['data']['id']).className="praiseb_yes";
							$$("praise_c_"+data['data']['id']).className="praise";
							$$("praise_c_"+data['data']['id']).innerHTML = data['data']['nick']+"等"+pn+"人觉得很赞";
						}else{
							uexWindow.toast("0","5",data['msg'],1000);
						}
					}else if(opId==3){//删除
						if(data['success']=='NOTLOGIN'){
							gologin();
						}else if(data['success']=='OK'){
							uexWindow.toast("0", "5", '删除成功~', 1000);
							getMain(0);
						}else{
							uexWindow.toast("0","5",data['msg'],1000);
						}
					}
				}else if(status == -1){
					if (opId == 0) {
						$$('main').className = 'errer';
						uexWindow.toast("0", "5", '加载失败', 1000);
					}else if (opId == 1) {
						uexWindow.toast("0", "5", '加载失败', 1000);
					}else if (opId == 2) {
						uexWindow.toast("0", "5", '赞失败', 1000);
					}else if (opId == 3) {
						uexWindow.toast("0", "5", '删除失败', 1000);
					}else if (opId == -1) {
						uexWindow.toast("0", "5", '图片发布失败', 1000);
						getMain(0);
					}
				}
			}
			
			getMain(0);
		}
	}
	
	function InsertHtml(data){
		if(!isDefine(data)){
			return false;
		}
		var list = data;
		for(i=0;i<list.length;i++){
			if(i==(list.length-1)){
				if(localStorage['talk_list_order']==0){
					min=list[i]['id'];
				}else if(localStorage['talk_list_order']==1){
					min=list[i]['retime'];
				}
			}
			var Div;
			Div=document.createElement("div");
			Div.className='talkitem';
			var html ='<div class="avatar" onclick="javascript:user_talk('+list[i]['userid']+',\''+list[i]['nickname']+'\');">';
			if(list[i]['avatar'].length>10){
				html +='<img src="'+list[i]['avatar']+'">';
			}
			html +='</div>';
	        html +='<div class="talkcontent">'+
	               ' 	<h3 onclick="javascript:jump('+list[i]['id']+');">'+list[i]['nickname']+'</h3>'+
				   '	<div class="date" onclick="javascript:jump('+list[i]['id']+');">'+list[i]['addtime']+'  '+list[i]['address']+'</div>';
			
			if(list[i]['photos'].length==1){//单图
	        	html +='<div class="img talkloadimg" ontouchstart="zy_touch(\'down\')" onclick="ImageBrowser(\''+list[i]['photoshd']+'\',0);">'+
	                   '   <img src="'+list[i]['photos'][0]+'" class="hide" onload="loading(this)">'+
				       '</div>';
			}else if(list[i]['photos'].length>1){//多图
				html +='<div class="imgs">';
				for(n=0;n<list[i]['photos'].length;n++){
	                 html +='<div class="talkloadimg"  ontouchstart="zy_touch(\'down\')" onclick="ImageBrowser(\''+list[i]['photoshd']+'\','+n+',1);"><img src="'+list[i]['photos'][n]+'" class="hide" onload="loading(this)"></div>';
			    }
				html +='<span class="clear"></span></div>';
			}
			if(list[i]['voice']!=''){
				html +='<div class="voice" id="voice'+list[i]['id']+'" ontouchstart="zy_touch(\'down\')" onclick="audioPlay(\''+list[i]['voice']+'\',\'voice'+list[i]['id']+'\');"><span>28”</span></div>';
			}
	        html +=' 	<p id="content_'+list[i]['id']+'">'+list[i]['content']+'</p>';
			html +='    <div class="btns">';
			if (typeof(localStorage['u_id'])!= "undefined") {
				if (list[i]['userid'] == localStorage['u_id']) {
					html += '<div class="date" onclick="javascript:del(' + list[i]['id'] + ');">删除</div>';
				}else{
					html +='<div class="date"></div>';
				}
			}else{
				html +='<div class="date"></div>';
			}
			
			html +=' 		<span class="praiseb" id="praise_'+list[i]['id']+'" ontouchstart="zy_touch(\'down\')" onclick="praise('+list[i]['id']+');">'+list[i]['praise']+'</span>';
			html +=' 	    <span class="commentb" ontouchstart="zy_touch(\'down\')" onclick="commentb('+list[i]['id']+','+list[i]['userid']+',\''+list[i]['nickname']+'\');">'+list[i]['renum']+'</span>';
			html +=' 	</div>';
			   
			
			html +='<div id="re_c_'+list[i]['id']+'" class="rec">';
			if(list[i]['praisedata'].length>0){
				html +='<div id="praise_c_'+list[i]['id']+'" class="praise">';
				for(j=0;j<list[i]['praisedata'].length;j++){
					if(j>0){
						html +=',';
					}
					html +=list[i]['praisedata'][j]['nick'];
				}
				html +='等'+list[i]['praise']+'人觉得很赞</div>';
			}else{
				html +='<div id="praise_c_'+list[i]['id']+'"></div>';
			}
			
			if(list[i]['reply'].length>0){
				for(j=0;j<list[i]['reply'].length;j++){
					html +='<div class="prccontent" ontouchstart="zy_touch(\'down\')" onclick="commentb('+list[i]['id']+','+list[i]['reply'][j]['userid']+',\''+list[i]['reply'][j]['nick']+'\',\''+list[i]['content']+'\');"><span>'+list[i]['reply'][j]['nick']+'</span>回复<span>'+list[i]['reply'][j]['reply_nick']+':</span>'+list[i]['reply'][j]['content']+'</div>';
				}
			}
			html +='</div>';
			
			
			html +='</div>';
			Div.innerHTML= html;
			$$('main').appendChild(Div);
		}
	}
	
	function loading(obj){
		obj.className='';
		var par=obj.parentNode;
		par.className += ' nobg';  
	}

	function commentb(id,r_userid,r_nick){
		localStorage['answer']='talk';
		localStorage['talk_id']=id;
		localStorage['reply_userid']=r_userid;
		localStorage['reply_nick']=r_nick;
		localStorage['talk_content']=$$('content_'+id).innerHTML;
		
		uexWindow.open('talk_answer','0','talk_answer.html','2','', '',0);
	}
	
	</script>
</html>